import 'package:flutter/material.dart';
import 'package:magic_car/assessment/assessment.dart';
import 'package:magic_car/assessment/assessmentResult.dart';
import 'package:magic_car/authinspcter/submitauthcarinfo.dart';
import 'package:magic_car/jiance/editresult.dart';
import 'package:magic_car/jiance/inspectresults.dart';
import 'package:magic_car/jiance/inspectstart.dart';
import 'package:magic_car/jiance/insurance.dart';
import 'package:magic_car/jiance/obdinspect.dart';
import 'package:magic_car/jiance/papularInspects.dart';
import 'package:magic_car/jiance/pricedifrent.dart';
import 'package:magic_car/jiance/start.dart';
import 'package:magic_car/util/HttpHelper.dart';
import 'package:magic_car/util/colors.dart';
import 'package:magic_car/util/config.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:toast/toast.dart';
import 'package:url_launcher/url_launcher.dart';

class JIanceDetailPage extends StatefulWidget {
  final String oid;
  JIanceDetailPage(this.oid);
  State<StatefulWidget> createState() {
    return new DetailState(this.oid);
  }
}

class DetailState extends State<JIanceDetailPage> {
  final String oid;
  DetailState(this.oid);
  List formList;
  Map order_info = new Map();
  String price = "0.00";
  String status = "订单状态";
  String order_sn = "订单编号";
  String handelStr = "开始检测";
  String statuscode = "0";
  String income = "0.00";
  String peifu = "0.00";
  initState() {
    super.initState();
    formList = [
      {
        "title": '预约项目',
        'sub_title': '预约项目',
        'sub_color': Color.fromRGBO(27, 182, 251, 1)
      },
      {
        "title": '联系人',
        'sub_title': '联系人',
        'sub_color': Color.fromRGBO(27, 182, 251, 1)
      },
      {
        "title": '联系电话',
        'sub_title': '联系电话',
        'sub_color': Color.fromRGBO(27, 182, 251, 1)
      },
      {
        "title": '预约时间',
        'sub_title': '预约时间',
        'sub_color': Color.fromRGBO(27, 182, 251, 1)
      },
      {
        "title": '品牌',
        'sub_title': '品牌',
        'sub_color': Color.fromRGBO(27, 182, 251, 1)
      },
      {
        "title": '预约车型',
        'sub_title': '预约车型',
        'sub_color': Color.fromRGBO(27, 182, 251, 1)
      },
      {
        "title": '车价',
        'sub_title': '车价',
        'sub_color': Color.fromRGBO(27, 182, 251, 1)
      },
      {
        "title": '下单时间',
        'sub_title': '下单时间',
        'sub_color': Color.fromRGBO(27, 182, 251, 1)
      },
      // {
      //   "title": '担责',
      //   'sub_title': '下单时间',
      //   'sub_color': Color.fromRGBO(27, 182, 251, 1)
      // },
      // {
      //   "title": '下单时间',
      //   'sub_title': '下单时间',
      //   'sub_color': Color.fromRGBO(27, 182, 251, 1)
      // },
    ];
    loadOrderInfo();
  }

  Widget buildcontent() {
    List<Widget> tiles = [];
    print(formList);
    Widget content;
    for (var i = 0; i < formList.length; i++) {
      var item = formList[i];
      tiles.add(Padding(
          padding: new EdgeInsets.fromLTRB(0, 0, 0, 0),
          child: Container(
              // color: Colors.white,
              height: 30,
              child: new GestureDetector(
                  onTap: () async {
                    print('点击索引' + i.toString());
                    if (i == 2) {
                      //拨打电话
                      String url = 'tel:' + item['sub_title'];
                      if (await canLaunch(url)) {
                        await launch(url);
                      } else {
                        throw 'Could not launch $url';
                      }
                    }
                  },
                  child: new Row(
                    children: <Widget>[
                      Expanded(
                        child: new Padding(
                            padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                            child: new Text(
                              item['title'],
                              style: TextStyle(
                                  fontSize: 12,
                                  color: Color.fromRGBO(51, 51, 51, 1)),
                            )),
                        flex: 1,
                      ),
                      new Padding(
                          padding: new EdgeInsets.fromLTRB(0, 0, 10, 0),
                          child: new Text(
                            //'1212121',
                            item['sub_title'],
                            style: TextStyle(
                                fontSize: 12,
                                color: Color.fromRGBO(51, 51, 51, 1)),
                          )),
                    ],
                  )))));
    }
    // return tiles;
    content = new Column(
        children: tiles //重点在这里，因为用编辑器写Column生成的children后面会跟一个<Widget>[]，
        //此时如果我们直接把生成的tiles放在<Widget>[]中是会报一个类型不匹配的错误，把<Widget>[]删了就可以了
        );
    return content;
  }

  //设置订单开始
  setStart() {
    if (int.parse(order_info['price_difference_status']) == 1) {
      Toast.show('价格异常，请等待客户付款，再进行检测', context);
      return;
    }
    // Map<String, String> map = new Map();
    // map['id'] = this.oid;
    // //  SharedPreferences pref = await SharedPreferences.getInstance();
    // //  map["id"]=pref.getString('uid');
    // //  map["type"]="0";

    // HttpHelper.post(HttpHelper.API_UpdateOrderStart, (data) async {
    //   if (data != null) {
    //     print(data);
    //     if (data["code"].toString() == "1"||data["code"].toString() == "0") {
    //       Navigator.of(context)
    //                       .push(new MaterialPageRoute(builder: (_) {
    //                     return new Papularinspects(this.oid,1);
    //                   }));
    //     }
    //     if(data["code"].toString() == "2"||data["code"].toString() == "3"){
    //       Navigator.of(context)
    //                       .push(new MaterialPageRoute(builder: (_) {
    //                     return new PapularinspectReults(this.oid,1);
    //                   }));
    //     }
    //   }
    // }, params: map);
    if (statuscode == "0") {
      //StartPicPage
      // Navigator.of(context).push(new MaterialPageRoute(builder: (_) {
      //   return new StartPicPage(this.oid);
      // }));
      Navigator.of(context).push(new MaterialPageRoute(builder: (_) {
        return new StartPicPage(this.oid, order_info['test_type']);
      })).then((param) {
        loadOrderInfo();
      });
    }
    if (statuscode == "1" && this.order_info['is_start'] == '0') {
      if (order_info['pattern'].toString() == "5") {
        //认证检测
        if (order_info["bussiness_car_id"].toString() == "0") {
          Toast.show("请先录入车源信息", context);
          Navigator.of(context).push(new MaterialPageRoute(builder: (_) {
            return new BusinessAuthStartPage(1, this.oid,order_info['bussiness_id'].toString());
            // return new StartPicPage(this.oid, order_info['test_type']);
          })).then((param) {
            loadOrderInfo();
          });
        }else {
          //已经有车源信息
           Navigator.of(context).push(new MaterialPageRoute(builder: (_) {
          return new StartPicPage(this.oid, order_info['test_type']);
        })).then((param) {
          loadOrderInfo();
        });
        }
      } else {
        Navigator.of(context).push(new MaterialPageRoute(builder: (_) {
          return new StartPicPage(this.oid, order_info['test_type']);
        })).then((param) {
          loadOrderInfo();
        });
      }
      // Navigator.of(context).push(new MaterialPageRoute(builder: (_) {
      //   return new StartPicPage(this.oid);
      // }));
    }
    if (this.order_info['is_start'] == '1' && statuscode == "1") {
      if (order_info['test_type'] == '保修检测' &&
          order_info['obdfinsh'].toString() == '1' &&
          order_info['cancontinue'].toString() == '0') {
        Toast.show('请等待审核结果', context);
        return;
      }
      if (order_info['test_type'] == '保修检测' &&
          order_info['obdfinsh'].toString() == '1' &&
          order_info['cancontinue'].toString() == '2') {
        Toast.show('此订单不可保修', context);
        return;
      }
      Map param = {};
      // Map param = {'url':img_url,'attachment':attachment};
      Navigator.of(context).push(new MaterialPageRoute(builder: (_) {
        //    Map param = {
        //   "id": '9999',
        //   "post_id": '4000',
        //   "name": "人车合照",
        //   "status": 2,
        //   "stat": 1,
        //   "created_at": "2019-03-07 19:40:57",
        //   "updated_at": "2019-03-07 19:40:57",
        //   "ismust": 1,
        //   "url": this.order_info['photocache'],
        //   "url2": '',
        //   "item": '',
        // };
        if (order_info['test_type'] == '金融检测') {
          return new AssementPapularinspects(this.oid, 1, param);
        } else if (order_info['test_type'] == '保修检测') {
          if (order_info['obdfinsh'].toString() == '1') {
            return new InsurancePapularinspects(this.oid, 1, param, false);
          } else {
            return new OBDPage(this.oid);
          }
        } else {
          return new Papularinspects(this.oid, 1, param, false);
        }
      })).then((value) {
        loadOrderInfo();
      });
    }
    if (statuscode == "2" || statuscode == "3") {
      Map param = {
        "id": '9999',
        "post_id": '4000',
        "name": "人车合照",
        "status": 2,
        "stat": 1,
        "created_at": "2019-03-07 19:40:57",
        "updated_at": "2019-03-07 19:40:57",
        "ismust": 1,
        "url": this.order_info['photocache'],
        "url2": '',
        "item": '',
      };
      // Map param = {'url':img_url,'attachment':attachment};
      // Navigator.of(context).push(new MaterialPageRoute(builder: (_) {
      //   return new EditResult(this.oid, 1, param);
      // }));
      Navigator.of(context).push(new MaterialPageRoute(builder: (_) {
        if (order_info['test_type'] == '金融检测') {
          return new AssementinspectReults(this.oid, 1);
        } else
          return new PapularinspectReults(this.oid, 1);
      }));
    }
  }

  confirm() async {
    Map<String, String> map = new Map();
    map['id'] = this.oid;
    SharedPreferences pref = await SharedPreferences.getInstance();
    map["iid"] = pref.getString('uid');
    // map["type"]="0";

    HttpHelper.post(HttpHelper.API_Confirmorder, (data) async {
      if (data != null) {
        print(data);
        if (data['code'].toString() == '1') {
          Toast.show('订单已确认，请前往处理', context);
          // Navigator.pop(context);
          loadOrderInfo();
        }
      }
    }, params: map);
  }

  showAlert() {
    showModalBottomSheet(
        context: context,
        builder: (BuildContext context) {
          return Padding(
              padding: new EdgeInsets.fromLTRB(0, 0, 0, 0),
              child: Container(
                height: 130,
                child: new Column(children: <Widget>[
                  new Container(
                      decoration: new BoxDecoration(
                          border: Border(
                              bottom: BorderSide(
                                  width: 1, color: Color(0xffe5e5e5)))),
                      height: 50,
                      child: Center(
                          child: Text('确认订单后，请前往处理，不可取消！',
                              style: TextStyle(fontSize: 16)))),
                  new Container(
                      decoration: new BoxDecoration(
                          border: Border(
                              bottom: BorderSide(
                                  width: 1, color: Color(0xffe5e5e5)))),
                      height: 40,
                      child: new GestureDetector(
                          behavior: HitTestBehavior.opaque,
                          onTap: () async {
                            // Navigator.pop(context);
                            confirm();
                            Navigator.pop(context);
                          },
                          child: Center(
                              child: Text('确认接单',
                                  style: TextStyle(
                                      fontSize: 16, color: Colors.red))))),
                  new Container(
                      height: 40,
                      child: new GestureDetector(
                          behavior: HitTestBehavior.opaque,
                          onTap: () {
                            Navigator.pop(context);
                          },
                          child: Center(
                              child:
                                  Text('拒绝', style: TextStyle(fontSize: 16))))),
                ]),
              ));
        });
  }

  //加载订单信息
  loadOrderInfo() async {
    Map<String, String> map = new Map();
    map['oid'] = this.oid;
    //  SharedPreferences pref = await SharedPreferences.getInstance();
    //  map["id"]=pref.getString('uid');
    //  map["type"]="0";

    HttpHelper.post(HttpHelper.API_OrderDetail, (data) async {
      if (data != null) {
        if (data["code"].toString() == "1") {
          List oldlist = formList;
          var orderinfo = data["info"];
          for (var i = 0; i < oldlist.length; i++) {
            var item = oldlist[i];
            var str = "";
            if (i == 0)
              str = orderinfo["test_type"];
            else if (i == 1)
              str = orderinfo["name"];
            else if (i == 2)
              str = orderinfo["phone_num"];
            else if (i == 3)
              str = orderinfo["add_time"];
            else if (i == 4)
              //str = '暂无信息';
              str = orderinfo['brand_id'] != "0"
                  ? orderinfo["brand_string"]["name"]
                  : '暂无信息';
            else if (i == 5)
              // str = '暂无信息';
              str = orderinfo['cartype_id'] != "0"
                  ? orderinfo["cartype_string"]["name"]
                  : '暂无信息';
            else if (i == 6)
              //str = '0';
              str = orderinfo["carprice"] != null
                  ? orderinfo["carprice"].toString()
                  : '0.00';
            else if (i == 7) str = orderinfo["order_time"];

            item["sub_title"] = str;
          }
          String tempStr = "";
          String statu = data["info"]["status"];
          if (statu == "0") {
            tempStr = "待处理";
          } else if (statu == "1") {
            tempStr = "进行中";
            handelStr = "继续检测";
          } else if (statu == "2") {
            tempStr = "待评价";
            handelStr = "查看结果";
          } else {
            tempStr = "已完成";
            handelStr = "查看结果";
          }

          if (data["info"]["is_accept"] != '1') {
            handelStr = "确认订单";
          }
          setState(() {
            handelStr = handelStr;
            formList = oldlist;
            order_info = data["info"];
            price = data["info"]["orderPrice"];
            status = tempStr;
            order_sn = data["info"]["order_sn"];
            statuscode = statu;
            income = data['info'].containsKey('income_arr')
                ? data['info']['income_arr']['inspector'].toString()
                : '0.00';
            peifu = data['info'].containsKey('peifu_arr')
                ? data['info']['peifu_arr']['inspector'].toString()
                : '0.00';
          });
          //pref.setStringList('userinfo', data["info"]);

        }
      }
    }, params: map);
  }

  Future _refresh() async {
    loadOrderInfo();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          titleSpacing: 0,
          title: Text(
            '订单详情',
            style: TextStyle(color: Colors.white,fontSize: Config.title_size),
          ),
          backgroundColor: Colours.app_main,
          elevation: 0,
          iconTheme: new IconThemeData(color: Colors.white),
        ),
        body: Container(
          child: RefreshIndicator(
              onRefresh: _refresh,
              backgroundColor: Colors.blue,
              child: new ListView(
                children: <Widget>[
                  Container(
                    height: 150,
                    color: Colours.app_main,
                    child: Padding(
                      padding: new EdgeInsets.fromLTRB(15, 50, 15, 10),
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.start,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: <Widget>[
                          Padding(
                            padding: new EdgeInsets.all(10),
                            child: Text(
                              status,
                              style:
                                  TextStyle(fontSize: 18, color: Colors.white),
                            ),
                          ),
                          Padding(
                            padding: new EdgeInsets.all(10),
                            child: Text(
                              '订单编号：' + order_sn,
                              style:
                                  TextStyle(fontSize: 13, color: Colors.white),
                            ),
                          )
                        ],
                      ),
                    ),
                  ),
                  Container(
                    height: 10,
                    color: Color.fromRGBO(238, 238, 238, 1),
                  ),
                  Padding(
                      padding: new EdgeInsets.fromLTRB(13, 15, 15, 15),
                      child: Container(
                          // padding: new EdgeInsets.all(15),
                          height: 20,
                          // color: Color.fromRGBO(27, 182, 251, 1),
                          child: new Text(
                            '1',
                            style: TextStyle(
                              color: Colours.app_main,
                              backgroundColor: Colours.app_main,
                            ),
                          ))),
                  Padding(
                      padding: new EdgeInsets.fromLTRB(15, 1, 15, 15),
                      child: buildcontent()),
                  Padding(
                    padding: new EdgeInsets.fromLTRB(0, 15, 25, 10),
                    child: Align(
                      alignment: Alignment.centerRight,
                      child: Text(
                        '检测金额：¥' + price,
                        style: TextStyle(
                            fontSize: 12, color: Color.fromRGBO(51, 51, 51, 1)),
                      ),
                    ),
                  ),
                  priceProblem(),
                  int.parse(statuscode) > 1
                      ? Padding(
                          padding: new EdgeInsets.fromLTRB(0, 0, 25, 10),
                          child: Align(
                            alignment: Alignment.centerRight,
                            child: Text(
                              '收益金额：¥' + income,
                              style: TextStyle(
                                  fontSize: 12,
                                  color: Color.fromRGBO(51, 51, 51, 1)),
                            ),
                          ),
                        )
                      : new Container(height: 0),
                  int.parse(statuscode) > 1
                      ? Padding(
                          padding: new EdgeInsets.fromLTRB(0, 0, 25, 10),
                          child: Align(
                            alignment: Alignment.centerRight,
                            child: Text(
                              order_info['test_type'] == '保修检测'
                                  ? '担责金额：请查看担责说明':
                                    double.parse(peifu)>100?"担责比例：¥${peifu}":"担责比例：${peifu}%",
                              // '担责金额：'+ order_info['test_type']=='保修检测'?'请查看担责说明' :'¥' + peifu,
                              style: TextStyle(
                                  fontSize: 12,
                                  color: Color.fromRGBO(51, 51, 51, 1)),
                            ),
                          ),
                        )
                      : new Container(height: 0),

                  // Padding(padding: new EdgeInsets.fromLTRB(30,10,10,10),child:
                  // new Column(
                  //   mainAxisAlignment: MainAxisAlignment.start,
                  //   crossAxisAlignment: CrossAxisAlignment.start,
                  //   children: <Widget>[
                  //     Text('订单收益：¥1000'),
                  //     Text('担责详情'),
                  //   ]
                  // )

                  // ),

                  order_info["canedit"].toString() == "1" &&
                          int.parse(order_info['status']) > 1
                      ? Padding(
                          padding: new EdgeInsets.fromLTRB(35, 20, 35, 0),
                          child: SizedBox(
                              width: double.infinity,
                              height: 50,
                              child: new RaisedButton.icon(
                                icon: new Image.asset(
                                    'resource/images/user/answer.png'),
                                label: Text(
                                  '编辑检测信息',
                                  style: TextStyle(fontSize: 15),
                                ),
                                color: Color.fromRGBO(33, 192, 193, 1),
                                textColor: Colors.white,
                                onPressed: () {
                                  // Map param = {};
                                  // // Map param = {
                                  // //   "id": '9999',
                                  // //   "post_id": '4000',
                                  // //   "name": "人车合照",
                                  // //   "status": 2,
                                  // //   "stat": 1,
                                  // //   "created_at": "2019-03-07 19:40:57",
                                  // //   "updated_at": "2019-03-07 19:40:57",
                                  // //   "ismust": 1,
                                  // //   "url": this.order_info['photocache'],
                                  // //   "url2": '',
                                  // //   "item": '',
                                  // // };

                                  // Navigator.of(context)
                                  //     .push(new MaterialPageRoute(builder: (_) {
                                  //   return new Papularinspects(
                                  //       this.oid, 1, param, true);
                                  // }));
                                  Map param = {};
                                  // Map param = {'url':img_url,'attachment':attachment};
                                  Navigator.of(context)
                                      .push(new MaterialPageRoute(builder: (_) {
                                    //    Map param = {
                                    //   "id": '9999',
                                    //   "post_id": '4000',
                                    //   "name": "人车合照",
                                    //   "status": 2,
                                    //   "stat": 1,
                                    //   "created_at": "2019-03-07 19:40:57",
                                    //   "updated_at": "2019-03-07 19:40:57",
                                    //   "ismust": 1,
                                    //   "url": this.order_info['photocache'],
                                    //   "url2": '',
                                    //   "item": '',
                                    // };
                                    if (order_info['test_type'] == '金融检测') {
                                      return new AssementPapularinspects(
                                          this.oid, 1, param);
                                    } else if (order_info['test_type'] ==
                                        '保修检测') {
                                      if (order_info['obdfinsh'].toString() ==
                                          '1') {
                                        return new InsurancePapularinspects(
                                            this.oid, 1, param, false);
                                      } else {
                                        return new OBDPage(this.oid);
                                      }
                                    } else {
                                      return new Papularinspects(
                                          this.oid, 1, param, false);
                                    }
                                  })).then((value) {
                                    loadOrderInfo();
                                  });
                                },
                              )),
                        )
                      : new Container(height: 0),

                  Padding(
                    padding: new EdgeInsets.fromLTRB(35, 20, 35, 20),
                    child: SizedBox(
                        width: double.infinity,
                        height: 50,
                        child: new RaisedButton.icon(
                          icon: new Image.asset(
                              'resource/images/user/answer.png'),
                          label: Text(
                            handelStr,
                            style: TextStyle(fontSize: 15),
                          ),
                          color: Colours.app_main,
                          textColor: Colors.white,
                          onPressed: () {
                            if (int.parse(order_info["is_accept"]) == 0) {
                              showAlert();
                            }
                            if (int.parse(order_info["is_accept"]) == 1)
                              setStart();
                          },
                        )),
                  )
                ],
              )),
        ));
  }

  Widget priceProblem() {
    if (int.parse(statuscode) == 1) {
      if (int.parse(order_info['price_difference_status']) == 0) {
        //没有改过时可以更改价格
        return Padding(
            padding: new EdgeInsets.fromLTRB(0, 5, 25, 10),
            child: GestureDetector(
              onTap: () {
                Navigator.of(context).push(new MaterialPageRoute(builder: (_) {
                  return new PriceDiffrentPage(this.oid);
                })).then((param) {
                  loadOrderInfo();
                });
              },
              child: Align(
                alignment: Alignment.centerRight,
                child: Text(
                  '订单金额异常？',
                  style: TextStyle(fontSize: 12, color: Colors.red),
                ),
              ),
            ));
      } else if (int.parse(order_info['price_difference_status']) == 1) {
        return Padding(
            padding: new EdgeInsets.fromLTRB(0, 5, 25, 10),
            child: GestureDetector(
              onTap: () {
                showCancel();
              },
              child: Align(
                alignment: Alignment.centerRight,
                child: Text(
                  '等待用户付款，点击可撤销',
                  style: TextStyle(fontSize: 12, color: Colors.red),
                ),
              ),
            ));
      } else {
        return Padding(
            padding: new EdgeInsets.fromLTRB(0, 5, 25, 10),
            child: GestureDetector(
              onTap: () {},
              child: Align(
                alignment: Alignment.centerRight,
                child: Text(
                  '价格已更改',
                  style: TextStyle(fontSize: 12, color: Colors.red),
                ),
              ),
            ));
      }
    } else {
      return Container(height: 0);
    }
  }

  showCancel() {
    showModalBottomSheet(
        context: context,
        builder: (BuildContext context) {
          return Padding(
              padding: new EdgeInsets.fromLTRB(0, 0, 0, 0),
              child: Container(
                height: 130,
                child: new Column(children: <Widget>[
                  new Container(
                      decoration: new BoxDecoration(
                          border: Border(
                              bottom: BorderSide(
                                  width: 1, color: Color(0xffe5e5e5)))),
                      height: 50,
                      child: Center(
                          child: Text('确认取消更改价格？',
                              style: TextStyle(fontSize: 16)))),
                  new Container(
                      decoration: new BoxDecoration(
                          border: Border(
                              bottom: BorderSide(
                                  width: 1, color: Color(0xffe5e5e5)))),
                      height: 40,
                      child: new GestureDetector(
                          behavior: HitTestBehavior.opaque,
                          onTap: () async {
                            // Navigator.pop(context);
                            cancelPriceChange();
                            Navigator.pop(context);
                          },
                          child: Center(
                              child: Text('确认',
                                  style: TextStyle(
                                      fontSize: 16, color: Colors.red))))),
                  new Container(
                      height: 40,
                      child: new GestureDetector(
                          behavior: HitTestBehavior.opaque,
                          onTap: () {
                            Navigator.pop(context);
                          },
                          child: Center(
                              child:
                                  Text('取消', style: TextStyle(fontSize: 16))))),
                ]),
              ));
        });
  }

  cancelPriceChange() {
    Map<String, String> map = new Map();
    map['oid'] = this.oid;

    HttpHelper.post(HttpHelper.API_CancelPrice, (data) async {
      if (data != null) {
        print(data);
        Toast.show(data['msg'], context);
        if (data['code'].toString() == '1') {
          loadOrderInfo();
        } else {}
      }
    }, params: map);
  }
}
